/**
 * Created by jiangtao on 16/5/3.
 */
(function(){
    var dom = $('body');
    //创业必备
    function cy(){
        dom.on('click','*[data-target="cy"]',cyChange);
        var keepGoing = true;
        function cyChange(e){
            var self = this;
            if(!keepGoing) return;
            keepGoing = false;
            $('*[data-target="cy"]').each(function(index,dom){
                if(dom == self) {
                    $(dom).parents('li').addClass('active');
                    moveX(e,index);
                    changeItem(index);
                } else {
                    $(dom).parents('li').removeClass('active');
                };
            });
        };
        function moveX(e,index){
            var pageX = $(e.target).offset().left - $('.bule-line-two').offset().left;
            var targrtWidth = $(e.target).width() + 10;
            $('.biao-s').animate({
                left:pageX  + targrtWidth / 2 + 'px'
            },function(){
                keepGoing = true;
            });
        };
        function changeItem(i){
            console.log(i)
            $('.server-lei-box').each(function(index,dom){
                if(i == index){
                    $(dom).removeClass('hide');
                } else {
                    $(dom).addClass('hide');
                };
            });
        };
    };
    cy();

})()